//
//  cartoonDestailTableViewCell.m
//  A段项目,漫画
//
//  Created by dllo on 15/4/23.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "cartoonDestailTableViewCell.h"
#define WIDTH [[UIScreen mainScreen] bounds].size.width
@implementation cartoonDestailTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.cartoonImage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.cartoonImage];
        [self.cartoonImage release];
        
        self.title = [[UILabel alloc] init];
        [self.contentView addSubview:self.title];
        [self.title release];
        
        self.artist_name = [[UILabel alloc] init];
        [self.contentView addSubview:self.artist_name];
        [self.artist_name release];
        
        self.grade_ave = [[UILabel alloc] init];
        [self.contentView addSubview:self.grade_ave];
        [self.grade_ave release];
        
        self.type = [[UILabel alloc] init];
        [self.contentView addSubview:self.type];
        [self.type release];
        
        self.saveButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.contentView addSubview:self.saveButton];
        
        self.readStartButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.contentView addSubview:self.readStartButton];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    //133   177
    CGFloat bili = 177.0 / 133;
    
    self.cartoonImage.frame = CGRectMake(20, 20, WIDTH / 3, WIDTH / 3 * bili);
    self.cartoonImage.layer.masksToBounds = YES;
    self.cartoonImage.layer.borderWidth = 1;
    self.cartoonImage.layer.cornerRadius = 15;
    self.cartoonImage.layer.borderColor = [UIColor clearColor].CGColor;
    
    
    self.title.font = [UIFont systemFontOfSize:18];
    self.title.frame = CGRectMake(WIDTH / 3 + 20 + 20, 20, WIDTH - (WIDTH / 3 + 20 + 20 + 10), 30);
    
    self.artist_name.frame = CGRectMake(WIDTH / 3 + 20 + 20, 50, WIDTH - (WIDTH / 3 + 20 + 20 + 10), 20);
    self.artist_name.font = [UIFont systemFontOfSize:14];
    
    self.type.frame = CGRectMake(WIDTH / 3 + 20 + 20, 70, WIDTH - (WIDTH / 3 + 20 + 20 + 10), 20);
    self.type.font = [UIFont systemFontOfSize:14];
    
    self.grade_ave.frame = CGRectMake(WIDTH / 3 + 20 + 20, 90, WIDTH - (WIDTH / 3 + 20 + 20 + 10), 20);
    self.grade_ave.font = [UIFont systemFontOfSize:14];
    
    
    self.saveButton.frame = CGRectMake(WIDTH / 3 + 20 + 20, WIDTH / 3 * bili - 12, 32, 32);
    
    [self.saveButton addTarget:self action:@selector(saveButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.readStartButton.frame = CGRectMake(WIDTH / 3 + 20 + 20 + 32 + 30, WIDTH / 3 * bili - 12, 32, 32);
    [self.readStartButton setBackgroundImage:[UIImage imageNamed:@"iconfont-yuedu"] forState:UIControlStateNormal];
    [self.readStartButton addTarget:self action:@selector(readStartButton:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)saveButtonAction:(UIButton *)button{
    [self.delegate saveCartoon];
}

- (void)readStartButton:(UIButton *)button{
    self.myBlock(self.readStartButton.titleLabel.text);
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
